import 'package:flutter/material.dart';

class Animated2Page extends StatefulWidget {

  const Animated2Page({super.key});

  @override
  State<Animated2Page> createState() => _Animated2PageState();

}

class _Animated2PageState extends State<Animated2Page> with SingleTickerProviderStateMixin{

  late AnimationController _controller;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = AnimationController(
      vsync: this,
      duration: Duration(seconds: 2),//持续时间
      lowerBound: 0.1,//最小值
      upperBound: 1.0,//最大值
    )..repeat(reverse: true);
  }

  @override
  void dispose() {
    // TODO: implement dispose
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: (){
          _controller.reset();
        },
        child: Icon(Icons.add),
      ),
      body: Center(
        child: Column(
            children: [
              SizedBox(height: 40,),
              // 透明度动画
              FadeTransition(
                opacity: _controller,
                child: FlutterLogo(size: 120,),),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  ElevatedButton(onPressed: (){
                    _controller.reset();
                  }, child: Text("reset")),
                  ElevatedButton(onPressed: (){
                    _controller.repeat();
                  }, child: Text("repeat")),
                  ElevatedButton(onPressed: (){
                    _controller.stop();
                  }, child: Text("stop")),
                  ElevatedButton(onPressed: (){
                    _controller.reverse();
                  }, child: Text("reverse")),
                  ElevatedButton(onPressed: (){
                    _controller.forward();
                  }, child: Text("forward")),
                ],
              )
            ]
        ),
      ),
    );
  }
}
